 data   SEGMENT
   handle1   DW   0
   handle2   DW   0
   file1     DB   'A:\ASM\INPUT.DAT',0
   file2     DB   'A:\ASM\OUTPUT.DAT',0
   databuf   DB    1 DUP (?)
   mes1      DB   'File opening error$'
   mes2      DB   'File reading error$'
   mes3      DB   'File write error$'
 data  ENDS

 code  SEGMENT

      ASSUME   CS : code , DS : data

   open        :  MOV AH , 3Dh
                  MOV AL , 0
                ;  MOV DX , seg file1
                ;  MOV DS , DX
                  MOV DX , OFFSET file1
                  INT 21h
                  JC  open_error
                  MOV handle1 , AX

                  MOV AH , 3Ch
                  MOV DX , OFFSET file2
                  INT 21h
                  JC  open_error
                  MOV handle2 , AX

                  MOV AH , 3Dh
                  MOV AL , 1
                 ; MOV DX , seg file2
                 ; MOV DS , DX
                  MOV DX , OFFSET file2
                  INT 21h
                  JC   open_error
                  MOV handle2 , AX

   read        :  MOV AH , 3Fh
                  MOV BX , handle1
                  MOV CX , 1
                  ;MOV DX , seg databuf
                  ;MOV DS , DX
                  MOV DX , OFFSET databuf
                  INT 21h
                  JC   read_error

   write       :  MOV AH , 40h
                  MOV BX , handle2
                  MOV CX , 1
                 ; MOV DX , seg databuf
                 ; MOV DS , DX
                  MOV DX , offset databuf
                  INT 21h
                  JC  write_error

   open_error  :  MOV AH , 09h
                  LEA DX , mes1
                  INT 21h
                  JMP end

   read_error  :  MOV AH , 09h
                  LEA DX , mes2
                  INT 21h
                  JMP end

   write_error :  MOV AH , 09h
                  LEA DX , mes2
                  INT 21h
                  JMP end

   end         :  MOV AH , 4Ch
                  INT 21h

 code  ENDS
       END  open
